package com.briup.shopadmin.web.controller;

import com.briup.shopadmin.common.Result;
import com.briup.shopadmin.common.bean.User;
import com.briup.shopadmin.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RequestMapping("user")
@Api(tags = "会员管理相关接口")
@RestController
public class UserController {
    @Autowired
    IUserService userService;

    @GetMapping("findUserInfo")
    @ApiOperation("查询所有会员信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName",value = "会员名称",defaultValue = ""),
            @ApiImplicitParam(name = "pageNum",value = "页码",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每⻚展示数据条数",required = true)
    })
    public Result findUserInfo(@RequestParam(defaultValue = "",required = false) String userName, Integer pageNum, Integer pageSize
    ){
        Page<User> page = userService.findUserInfo(userName, pageNum, pageSize);
        return  Result.success(page);

    }
    @PutMapping("disable/{id}")
    @ApiOperation("禁用会员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户编号",required =  true)
    })
    public Result disable(@PathVariable long id){
        userService.disable(id);
        return  Result.success();
    }

    @PutMapping("enable/{id}")
    @ApiOperation("启用会员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户编号",required =  true)
    })
    public Result enable(@PathVariable long id){
        userService.enable(id);
        return  Result.success();
    }
}
